var app = getApp();
const Zan = require('../../../dist/index');

Page(Object.assign({}, Zan.Dialog, Zan.TopTips, {
	data: {
		user: {}
	},

	onLoad: function (options) {
		var that = this;
		that.userinfo();
	},

	onReady: function () {

	},

	onShow: function () {
		var that = this;
		that.userinfo();
	},

	onHide: function () {

	},

	onPullDownRefresh: function () {
		var that = this;
		wx.showNavigationBarLoading();
		that.userinfo(function () {
			wx.hideNavigationBarLoading();
			wx.stopPullDownRefresh();
		});
	},

	userinfo: function (fn) {
		var that = this;

		// get userinfo
		app.battery.findOne('member/detail', app.data.member.id).then(function (r) {
			that.setData({
				user: {
					balance: (r.walletMoney - r.tradeMoney).toFixed(2),
					avatar: r.avatar,
					nickName: r.name,
					bindWebchat: r.bindWebchat,
					checkIdcard: r.checkIdcard,
					checkMobile: r.checkMobile,
					foregiftMoney: r.foregiftMoney,
					networkActive: r.networkActive,
					payForegift: r.payForegift,
					payWallet: r.payWallet
				}
			});
			fn && fn();
		}).catch(function (e) {
			that.showZanTopTips(e.message, {type: 'error'});
			fn && fn();
		});
	},

	deactivation: function () {
		var that = this;

		app.data.isMapCabinet = false;
		//back to map show deactivation
		wx.navigateBack({
			delta: 1
		})
	},

	payDeposit: function () {
		var that = this;

		app.wechat.payDeposit().then(function (d) {
			console.log(d);
		}).catch(function (e) {
			that.showZanTopTips(e.message, {type: 'error'});
		});
	},

	returnDeposit: function () {
		wx.showModal({
			title: '退押金',
			content: '请到指定网点办理退款',
			success: function(res) {
				if (res.confirm) {
					console.log('用户点击确定')
				} else if (res.cancel) {
					console.log('用户点击取消')
				}
			}
		})
	}

}));